home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CAWindow.cpp
-
- Contains: Window management code for CALib
-
- Written by: Jens Alfke, Rick Badertscher
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <21> 5/19/95 SJF Clean up CAGetFront...Window calls
- <16> 5/15/95 RB Adding CA_CATCH
- <15> 5/6/95 SJF WWDC bug fix session with Rick
- <11> 5/5/95 SJF Remove include of PartWrap.xh
- <10> 4/22/95 RB Enabling & Fixing CARegisterFloatingWindow()
- <8> 4/19/95 RB Fixing CAInstallWindowActivateHandler to call the
- Proxy Extension
- <7> 4/07/95 RB Small mods to CARegisterRootWindow()
- <6> 4/01/95 RB Added support for CAWindowActivateProc callback.
- <5> 3/31/95 RB Fixed bug in CARegisterRootWindow()
- Added support for multiple document partitions
- <4+> 2/28/95 SJF Add debug stuff to API calls
- <4> 2/20/95 SJF Merge in changes from RickB
- <3> 2/13/95 SJF Interim checkin to update project database
- <2) 12/15/94 SJF change somGetGlobalEnvironment to _gpProxyShell->GetGlobalEnvironment
- <1> 10/30/94 GCA,DHN All mods to make project compile with no
- errors under OpenDoc b1 (with SOM).
- <0> 10/30/94 SV SOMverted
-
- To Do:
- */
-
- #ifndef _CASESSN_
- #include "CASessn.h"
- #endif
-
- #ifndef _CAERROR_
- #include "CAError.h"
- #endif
-
- #ifndef _CADEBUG_
- #include "CADebug.h"
- #endif
-
- #ifndef _CADOCPRIV_
- #include "CADocPriv.h"
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODWindowIterator_xh
- #include <WinIter.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _StdTypIO_
- #include <StdTypIO.h>
- #endif
-
- #ifndef _CAPROXYPARTDEF_
- #include "CAProxyPartDef.h"
- #endif
-
- #ifndef CAProxyExtension_API
- #include "CAProxyExtension.xh"
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
-
- #pragma segment CALib
-
-
- //-------------------------------------------------------------------------
- // Static variables
- //-------------------------------------------------------------------------
-
-
- static CAWindowActivateHandler gWindowActivateHandler = NULL;
-
-
- //-------------------------------------------------------------------------
- // Window Management
- //-------------------------------------------------------------------------
-
-
- pascal Boolean
- CAIsPartWindow( WindowPtr window )
- {
- Environment* ev = gCASession->GetEV();
- ODWindowState* windowState = gCASession->GetODSession()->GetWindowState(ev);
- Boolean retval = false;
-
- if (window == NULL)
- return false; // Not a window!
- else if (((WindowPeek)window)->windowKind < userKind)
- return false; // DA or dialog window!
- else
- {
-
- CA_TRY
-
- TempODWindow tempWindow = windowState->AcquireODWindow(ev, window);
-
- if (tempWindow && !tempWindow->IsFloating(ev) && !tempWindow->IsRootWindow(ev) )
- retval = true;
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- }
-
- return (retval);
- }
-
-
- //-------------------------------------------------------------------------
-
- pascal WindowPtr
- CAGetFrontDocWindow( void )
- {
-
- Environment* ev = gCASession->GetEV();
- WindowPtr macWindow = kODNULL;
-
- CA_TRY
-
- TempODWindow tempWindow = gCASession->GetODSession()->GetWindowState(ev)->AcquireActiveWindow(ev);
-
- if (tempWindow)
- macWindow = tempWindow->GetPlatformWindow(ev);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- return macWindow;
-
- }
-
-
- //-------------------------------------------------------------------------
-
- pascal WindowPtr
- CAGetFrontFloatingWindow( void )
- {
- Environment* ev = gCASession->GetEV();
- WindowPtr macWindow = kODNULL;
-
- CA_TRY
-
- TempODWindow tempWindow = gCASession->GetODSession()->GetWindowState(ev)->AcquireFrontFloatingWindow(ev);
-
- if (tempWindow)
- macWindow = tempWindow->GetPlatformWindow(ev);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- return macWindow;
-
- }
-
-
- //-------------------------------------------------------------------------
-
- pascal void
- CASelectWindow( WindowPtr window )
- {
- Environment* ev = gCASession->GetEV();
-
- if (!window) return;
-
- CA_TRY
-
- TempODWindow tempWindow = gCASession->GetODSession()->GetWindowState(ev)->AcquireODWindow(ev, window);
-
- if (tempWindow)
- tempWindow->Select(ev);
- else
- SelectWindow(window);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- }
-
- #pragma segment Main
- pascal void CARegisterRootWindow( WindowPtr rootWindow,
- CADocumentRef document)
- {
- Environment* ev = gCASession->GetEV();
- ODWindowState* windowState = gCASession->GetODSession()->GetWindowState(ev);
- ODStorageUnit* rootPartSU = kODNULL;
- ODWindow* anODWindow = kODNULL;
- CADocument* docRef = kODNULL;
-
-
- docRef = (CADocument*) document;
-
- TempODFrame tempFrame = docRef->AcquireDisplayFrame();
-
- if (tempFrame)
- {
-
- CA_TRY
-
- anODWindow = windowState->RegisterWindowForFrame (ev, (ODPlatformWindow) rootWindow,
- tempFrame, kODTrue, kODTrue, kODFalse, kODTrue, kODFalse, kODNULL);
-
- THROW_IF_NULL (anODWindow);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- TRACE (3, "CARegisterRootWindow - draft contained display frame %x", anODWindow->GetRootFrame(ev));
-
-
- }
- else
- {
-
- CA_TRY
-
- TempODPart tempPart = docRef->AcquireRootPart();
-
- anODWindow = windowState->RegisterWindow (ev, (ODPlatformWindow) rootWindow,
- kODFrameObject, kODTrue, kODTrue, kODFalse, kODFalse, kODFalse, tempPart,
- gCASession->GetODSession()->Tokenize(ev, kODViewAsFrame),
- gCASession->GetODSession()->Tokenize(ev, kODPresDefault),
- (ODFrame*) kODNULL);
-
- THROW_IF_NULL (anODWindow);
-
- TRACE (3, "CARegisterRootWindow - root frame created, %x", anODWindow->GetRootFrame(ev));
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- }
-
- TRACE (3, "CARegisterRootWindow - window, %x", anODWindow);
-
- docRef->SetWindow(anODWindow);
-
- anODWindow->Open(ev);
- anODWindow->Show(ev);
- anODWindow->Select(ev);
- anODWindow->Release(ev);
-
- }
-
- pascal void CARegisterFloatingWindow(WindowPtr floatingWindow)
- {
-
- Environment* ev = gCASession->GetEV();
- ODWindowState* windowState = gCASession->GetODSession()->GetWindowState(ev);
- ODPart* floatingWindowHandlerPart;
- ODWindow* anODWindow;
-
- CA_TRY
-
- floatingWindowHandlerPart = gCASession->GetFloatingWindowHandlerPart ();
-
- anODWindow = windowState->RegisterWindow (ev, (ODPlatformWindow) floatingWindow,
- kODFrameObject, kODFalse, kODFalse, kODTrue, kODFalse, kODFalse, floatingWindowHandlerPart,
- gCASession->GetODSession()->Tokenize(ev, kODViewAsFrame),
- gCASession->GetODSession()->Tokenize(ev, kODPresDefault),
- (ODFrame*) kODNULL);
-
- THROW_IF_NULL (anODWindow);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- if (anODWindow)
- {
- anODWindow->Open(ev);
- anODWindow->Show(ev);
- anODWindow->Select(ev);
- anODWindow->Release(ev);
-
- }
-
- }
-
-
-
- pascal void CAUnregisterWindow( WindowPtr window )
- {
- Environment* ev = gCASession->GetEV();
- ODWindowState* windowState = gCASession->GetODSession()->GetWindowState(ev);
- ODWindow* anODWindow = kODNULL;
- CADocument* docRef;
-
- CA_TRY
-
- anODWindow = windowState->AcquireODWindow (ev, window);
- THROW_IF_NULL (anODWindow);
-
- // Hide the window so the OD window state doesn't muck with stuff
- HideWindow (window);
-
- if (anODWindow->IsFloating(ev))
- anODWindow->CloseAndRemove (ev);
- else
- {
- // FIrst have the root frame acquire focus
- CARequestStandardFocusSet (window);
-
- docRef = gCASession->FindCADocumentRefForWindow (anODWindow);
-
- if (docRef)
- {
-
- ODWindowIterator* iter = windowState->CreateWindowIterator(ev);
-
- for (ODWindow* window = iter->First(ev); iter->IsNotComplete(ev); window = iter->Next(ev))
- {
- if (( window != anODWindow) &&
- (ODObjectsAreEqual(ev,
- window->GetRootFrame(ev)->GetStorageUnit(ev)->GetDraft(ev),
- docRef->GetDraft() )))
- {
- window->Acquire(ev); // Close Releases
- window->Close(ev);
- }
- }
- ODDeleteObject(iter);
-
- anODWindow->CloseAndRemove (ev);
- }
- else
- anODWindow->CloseAndRemove (ev);
-
- }
-
- windowState->ActivateFrontWindows(ev);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
-
- }
-
-
- //-------------------------------------------------------------------------
-
- pascal OSErr CAInstallFloatingWindowHandlers ( CASelectWindowHandler handler1,
- CAFrontWindowHandler handler2,
- CAIsFloaterHandler handler3)
- {
- Environment* ev = gCASession->GetEV();
- OSErr result = noErr;
-
- CASelectWindowHandlerUPP handler1UPP;
- CAFrontWindowHandlerUPP handler2UPP;
- CAIsFloaterHandlerUPP handler3UPP;
-
- CA_TRY
-
- handler1UPP = (CASelectWindowHandlerUPP) NewRoutineDescriptor((ProcPtr)handler1,
- uppCASelectWindowHandlerInfo,
- GetCurrentISA());
-
- handler2UPP = (CAFrontWindowHandlerUPP) NewRoutineDescriptor((ProcPtr)handler2,
- uppCAFrontWindowHandlerInfo,
- GetCurrentISA());
-
- handler3UPP = (CAIsFloaterHandlerUPP) NewRoutineDescriptor((ProcPtr)handler3,
- uppCAIsFloaterHandlerInfo,
- GetCurrentISA());
-
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- return result;
-
- }
-
-
- //-------------------------------------------------------------------------
-
- pascal OSErr CAInstallWindowActivateHandler (CAWindowActivateHandler theHandler,
- CADocumentRef document)
- {
- Environment* ev = gCASession->GetEV();
- CAProxyExtension* proxyExt = kODNULL;
- OSErr result = noErr;
-
-
- CA_TRY
-
- TempODPart tempPart = ((CADocument*)document)->AcquireRootPart();
- proxyExt = (CAProxyExtension*)tempPart->AcquireExtension( ev, kCAProxyPartExtension );
-
- THROW_IF_NULL (proxyExt); // kODErrUnsupportedExtension
-
- CAWindowActivateHandlerUPP theUPPHandler;
- theUPPHandler = (CAWindowActivateHandlerUPP) NewRoutineDescriptor((ProcPtr)theHandler,
- uppCAWindowActivateHandlerInfo,
- GetCurrentISA());
-
- proxyExt->InstallCAWindowActivateHandler( ev, theUPPHandler);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- ODReleaseObject (ev, proxyExt);
-
- return result;
- }
-
-
-